export const $bgPath = 'https://static-1f1f5537-df24-4928-80f4-3a52a2899757.bspapp.com/bg'
export const $serverUrl = 'https://unidemo.dcloud.net.cn'

/**
 * 调用云函数
 * @param funcName
 * @param param
 * @param resDefault
 * @returns {Promise<T | never>}
 */
export async function uniFunc(funcName = '', param = {}, resDefault = {}){
  return uniCloud.callFunction({
    name: funcName,
    data: param,
  }).then(res => {
    return res.result.data
  }).catch((e) => {
    console.error(`e`, e)
    return Promise.reject(e)
  })
}

// clientDB 使用
const db = uniCloud.database() //代码块为cdb
/**
 * 调用clientDB
 * @param collectionName  参数 集合名称
 * @returns {Promise<void>}
 */
export function uniDB(collectionName){
  return db.collection(collectionName)
}

export const dbCmd = db.command

/**
 * 展示提示信息
 * @param title
 * @param time
 * @returns {Promise<any>}
 */
export function message(title = '', time = 1500){
  return new Promise((resolve, reject) => {
    uni.showToast({
      title: title,
      icon: 'none',
      mask: false,
      duration: time,
    })
    let timeId = setTimeout((res) => {
      resolve()
      clearTimeout(timeId)
    }, time)
  })
}

